cmake_minimum_required(VERSION 3.2)
message("build in ${CMAKE_SOURCE_DIR}")
# add this options before PROJECT keyword
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
project(drogon)


if(WIN32)
    enable_language(C CXX ASM_MASM)
    add_compile_options(/W4 /fp:fast /EHsc)
    add_link_options(/SAFESEH:NO)
else()
    enable_language(C CXX ASM)
endif()
if(UNIX)
    add_compile_options(-Wall -O2 -g3)
    if(APPLE)
        add_compile_options(-fno-pie)
    endif()
endif()

cmake_policy(SET CMP0054 NEW )
# Set RPATH-handing (CMake parameters)
set(CMAKE_SKIP_BUILD_RPATH OFF)
set(CMAKE_BUILD_WITH_INSTALL_RPATH OFF)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON)

# set macro-directory
list(APPEND CMAKE_MODULE_PATH
  "${CMAKE_SOURCE_DIR}/cmake/macros"
  "${CMAKE_SOURCE_DIR}/dep/cotire/CMake")


# build in Release-mode by default if not explicitly set
if( NOT CMAKE_BUILD_TYPE )
  set(CMAKE_BUILD_TYPE "RelWithDebInfo")
else()
  message("Build Type: ${CMAKE_BUILD_TYPE}")
endif()
include(CheckCXXSourceRuns)
include(CheckIncludeFiles)

include(cmake/options.cmake)
include(ConfigureBaseTargets)
include(CheckPlatform)
include(GroupSources)
include(AutoCollect)
include(FindPCHSupport)
include(BuildTarget)

find_package(Protobuf REQUIRED)
find_package(ZLIB REQUIRED)

include_directories(${Protobuf_INCLUDE_DIRS})
link_libraries(ZLIB::ZLIB protobuf::libprotobuf)

add_definitions(-D_DEF_USE_SPDLOG)

add_subdirectory(dep)
add_subdirectory(src)
